﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;

namespace DBModel.DAL
{
    public class HeadHunterDB
    {
        public static int InsertNewHeadHunter(HeadHunter headHunter)
        {
            DB.Context.Users.Add(headHunter);
            DB.Context.SaveChanges();
            return headHunter.UserId;
        }
        public static List<HeadHunter> GetAllHeadHunters()
        {
            return DB.Context.Users.OfType<HeadHunter>().Where(h => !h.IsDeleted).ToList();
        }
        public static HeadHunter GetHeadHunterById(int id)
        {
            var headhunter =
                (from h in DB.Context.Users.OfType<HeadHunter>()
                 where h.UserId == id && !h.IsDeleted
                 select h).SingleOrDefault();
            return headhunter;
        }
        public static bool DeleteHeadHunterById(int id)
        {
            HeadHunter user = HeadHunterDB.GetHeadHunterById(id);
            if (user != null)
            {
                user.IsDeleted = true;
                int affectedRows = DB.Context.SaveChanges();
                return (affectedRows > 0);
            }
            return false;
        }
    }
}
